import {
	getUserIdentity
} from "./utils"

const Key = 'XXXOXXXPXXEXXXNXXIXXD'
const KeyStatus = 'XXOP_STATUS'
const KeyCodeKey = 'KeyCodeKey'

export function getOpenid() {
	return uni.getStorageSync(Key) || null
}
export function setOpenid(data) {
	uni.setStorage({ //存到本地
		key: Key,
		data
	});
}

// 是否在请求code获取openid中 
// 1 请求中
// 0 空闲中
export function getOpenidStatus() {
	const {
		role
	} = getUserIdentity()
	const openIds = uni.getStorageSync(KeyStatus) || {}
	return openIds[role]
}

// 根据当前角色状态，存储对应的status
export function setOpenidStatus(data) {
	const {
		role
	} = getUserIdentity()
	const openIds = uni.getStorageSync(KeyStatus) || {}
	openIds[role] = data
	uni.setStorage({ //存到本地
		key: KeyStatus,
		data: openIds
	});
}

// 缓存code
export function setCode(data) {
	uni.setStorage({ //存到本地
		key: KeyCodeKey,
		data
	});
}

export function getCode() {
	return uni.getStorageSync(KeyCodeKey) || null
}